README for Kuokštytė, Ringailė, and Vytautas Kuokštis. "A spatiotemporal analysis of NATO member states’ defense spending: how much do allies actually free ride?" (for PSRM)

Updated: August 12, 2024

Notes: 
- The main text contains two figures, while all tables appear in the Supplementary materials, SM
- There are three scripts that should be run sequentially: 'Replication1', 'Replication2', and 'Replication3' (see 'SCRIPTS' below for more details)
- Note that ‘Replication1’must be executed before running this script to generate the figures correctly ('Replication2')
- Additional details about the data and the other files are provided in the ‘Data and Code Files Description’ document
- Also note that pre-defined spatial matrices are provided as generating them is time-intensive
- A (replication) log file, 'replication_log.txt', has also been generated, documenting the results for Tables 1 through 4
- The README file also includes details about the operating system, software, packages used, and additional information (all provided at the end of the document)


---------- SCRIPTS ------------
*Replication1_desc stat & main_models_Tables1-3.R: generates descriptive statistics (Table 1, SM) and runs the spatial and spatiotemporal models (referenced in Tables 2 and 3, SM)
*Replication2_simulation_free_riding_over_time.R: simulates the free-riding effect over time, producing Figures 1 and 2 in the main text
*Replication3_alternative_models_Table4.R: runs alternative spatiotemporal models (referenced in Table 4, SM)
*log_script.R: contains the script for saving all the results into a single .txt file  


---------- Saving tables (separately) ---------- 
*Note that the saving occurs after the replication code has been executed
*Reminder: the file 'log_script.R' contains the script for saving all the results into a single .txt file   
*Table 1 (SM), code: 
		write_xlsx(ds.df, "Table1_SM.xlsx")
*Table 2 (SM), code (saves the results into a .txt file): 
		capture.output(screenreg(list(sac.resc, sac.resc1991, sac.resc1999), stars = c(0.1, 0.05, 0.01), digits=3), file = "Table2_SM.txt")
*SR spatial effects, Table 2, code: 
		write_xlsx(m1.df, "Table2_SR spatial effects_SM.xlsx")
*Table 3 (SM), code (saves the results into a .txt file): 
		capture.output(screenreg(list(sacL.resc, sacL.resc1991, sacL.resc1999), stars = c(0.1, 0.05, 0.01), digits=3), file = "Table3_SM.txt")
*Spatial effects, Table 3, code: 
		write_xlsx(m2.df, "Table3_Spatial effects_SM.xlsx")
*Table 4 (SM), code (saves the results into a .txt file): 
		capture.output(screenreg(list(sacL.resc.no.us, sacL.resc1993.ru, sacL.resc1993.distru,sacL.dist.usneigh,sacL.rep1995), 
                         stars = c(0.1, 0.05, 0.01), digits=3), file = "Table4_SM.txt")


---------- Saving figures ---------- 
*Note that the saving occurs after the replication code has been executed
*Figure 1 (main text), code: ggsave("figure1.png", fig1)
*Figure 2 (main text), code: ggsave("figure2.png", fig2)

	
----------- Information on the OS, software, and the machine ----------- 
*Operating system and version: Windows 10 Pro, Version 22H2

*Software and version:
**RStudio**: Version 2024.04.2+764 ("Chocolate Cosmos" Release, 2024-06-05) 
**R**: Version 4.1.2 (2021-11-01)
**Quarto**: 1.4.555
**Browser Engine**: Chrome/120.0.6099.291 (Electron/28.3.1 Safari/537.36) 

*Amount of RAM on local machine: 8.00 GB (7.88 GB usable) 

----------- Packages ----------- 
*'readxl' (1.4.2) 
*'haven' (2.5.1) 
*'writexl' (1.4.2)
*'psych' (2.4.3)
*'tidyr' (1.3.0)  
*'dplyr' (1.1.2)
*'spdep' (1.2.8)
*'spatialreg' (1.2.8)
*'MASS' (7.3-57)
*'ggplot2' (3.4.2) 
*'tex_reg' (1.39.3)

